Vector3¶

represents point or position, velocity and scale. Note! Angular velocity can not be represented by this type, it should be represented by Transform. It is a class inheriting numpy.ndarray, so it is also ndarray.

In [1]:
from py3d import Vector3
Vector3()
Welcome to py3d world, please visit https://tumiz.github.io/scenario/ for more information
Out[1]:
Vector3([0., 0., 0.])
In [3]:
Vector3(x=1.2)
Out[3]:
Vector3([1.2, 0. , 0. ])
In [5]:
Vector3(x=1, y=3, z=-2.4)
Out[5]:
Vector3([ 1. ,  3. , -2.4])
In [7]:
Vector3(x=1, y=3, z=-2.4, n=(2,))
Out[7]:
Vector3([[ 1. ,  3. , -2.4],
         [ 1. ,  3. , -2.4]])

Get unit vector

In [9]:
Vector3().U
Out[9]:
Vector3([0., 0., 0.])

Get length

In [11]:
Vector3([1,2,3]).L
Out[11]:
array([3.74165739])
In [12]:
Vector3([
    [1,2,3],
    [4,5,6]]).L
Out[12]:
array([[3.74165739],
       [8.77496439]])

Get a random vector

In [14]:
Vector3.Rand()
Out[14]:
Vector3([0.44554818, 0.14620779, 0.82518622])

Get a random vector list

In [15]:
Vector3.Rand(3)
Out[15]:
Vector3([[0.27114678, 0.80159729, 0.84279109],
         [0.21441277, 0.19330337, 0.82606943],
         [0.83885225, 0.81112912, 0.68952938]])

Cross product

In [16]:
Vector3(x=3).cross(Vector3(y=2))
Out[16]:
Vector3([0., 0., 6.])

Display points

In [18]:
import plotly.express as px
p = Vector3.Rand(10).cumsum(axis=0)
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()

Use Vector3 as 2d vector

In [20]:
p=(Vector3.Rand(100)-0.5).U
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()